package com.yanqu.road.server.cmd.tradewar;

import com.yanqu.road.entity.tradewar.TradeWarSimpleNotice;
import com.yanqu.road.logic.pb.TradeWarPb;
import com.yanqu.road.pb.tradewar.TradeWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.TradeWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.S_TRADE_WAR_SIMPLE_NOTICE, desc = "商战简略公告")
public class TradeWarSimpleNoticeCmd extends AbstractCommand {

	private long userId;
	private long enemyUserId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		TradeWarProto.TradeWarSimpleNoticeReqMsg reqMsg = TradeWarProto.TradeWarSimpleNoticeReqMsg.parseFrom(packet.getBytes());
		userId = reqMsg.getUserId();
		enemyUserId = reqMsg.getEnemyUserId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

	}

	@Override
	public void sendData(GamePlayer player) {
		List<TradeWarSimpleNotice> dataList = TradeWarMgr.getTradeWarSimpleNoticeList(userId, enemyUserId);
		TradeWarProto.TradeWarSimpleNoticeRespMsg.Builder respMsg = TradeWarProto.TradeWarSimpleNoticeRespMsg.newBuilder();
		respMsg.setRet(ret);
		if(0 == ret){
			TradeWarProto.TradeWarSimpleNoticeListMsg.Builder listMsg = TradeWarPb.parseTradeWarSimpleNoticeListMsg(dataList);
			respMsg.setDataList(listMsg);
		}
		player.sendPacket(Protocol.U_TRADE_WAR_SIMPLE_NOTICE, respMsg);
	}
}
